﻿package mortal.common.shortcutsKey
{
    import com.gengine.keyBoard.*;
    import extend.language.*;

    public class KeyMapData extends Object implements IKeyMap
    {
        private var _keyData:KeyData;
        private var _keyMapName:String;
        private var _key:Object;
        private var _isCanEdit:Boolean;
        private var _tempName:String;
        public var displayKeyData:KeyData;
        private var _defaultKeyData:KeyData;

        public function KeyMapData(param1:Object, param2:String, param3:Boolean = true)
        {
            this._key = param1;
            this._keyMapName = param2;
            this._isCanEdit = param3;
            this.displayKeyData = new KeyData();
            return;
        }// end function

        public function get defaultKeyData() : KeyData
        {
            if (this._defaultKeyData == null)
            {
                this._defaultKeyData = ShortcutsKey.instance.getDefaultKeyData(this.key);
            }
            return this._defaultKeyData;
        }// end function

        public function set tempName(param1:String) : void
        {
            this._tempName = param1;
            return;
        }// end function

        public function get tempName() : String
        {
            if (this._tempName == null)
            {
                if (this._keyData)
                {
                    this._tempName = this._keyData.shortcutsName;
                }
                if (this._tempName == null)
                {
                    this._tempName = "";
                }
            }
            return this._tempName;
        }// end function

        public function get isCanEdit() : Boolean
        {
            return this._isCanEdit;
        }// end function

        public function get keyMapName() : String
        {
            return this._keyMapName;
        }// end function

        public function get key() : Object
        {
            return this._key;
        }// end function

        public function get keyData() : KeyData
        {
            return this._keyData;
        }// end function

        public function set keyData(param1:KeyData) : void
        {
            this._keyData = param1;
            if (this._keyData)
            {
                this.displayKeyData.isShift = this._keyData.isShift;
                this.displayKeyData.keyCode = this._keyData.keyCode;
            }
            else
            {
                this.displayKeyData.isShift = false;
                this.displayKeyData.keyCode = 0;
            }
            return;
        }// end function

        public function getServerObject() : Object
        {
            if (this._keyData)
            {
                return {c:this._keyData.keyCode, s:this._keyData.isShift == true ? (1) : (0)};
            }
            return null;
        }// end function

        public function setDefault() : void
        {
            if (this.keyData)
            {
                this.keyData.keyMap = null;
            }
            this.keyData = this.defaultKeyData;
            if (this.keyData)
            {
                this.keyData.keyMap = this;
                this.tempName = this.keyData.shortcutsName;
            }
            else
            {
                this.tempName = "";
            }
            return;
        }// end function

        public function updateKeyData() : void
        {
            if (this.keyData)
            {
                if (this.keyData.keyMap == this)
                {
                    this.keyData.keyMap = null;
                }
            }
            this.keyData = KeyBoardManager.createKeyData(this.displayKeyData.keyCode, this.displayKeyData.isShift);
            this.keyData.keyMap = this;
            return;
        }// end function

        public function recoveryKeyData() : void
        {
            if (this.keyData)
            {
                this.displayKeyData.keyCode = this.keyData.keyCode;
                this.displayKeyData.isShift = this.keyData.isShift;
                this.tempName = this.keyData.shortcutsName;
            }
            else
            {
                this.displayKeyData.keyCode = 0;
                this.displayKeyData.isShift = false;
                this.tempName = Language.getString(20334);
            }
            return;
        }// end function

        public function clear() : void
        {
            if (this.keyData)
            {
                this.keyData.keyMap = null;
                this.keyData = null;
            }
            this.tempName = Language.getString(20334);
            return;
        }// end function

    }
}
